package url;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;

public class download {
	public static void main(String[] args) throws Exception{
		System.out.println(InetAddress.getByName("localhost"));
		
		URL url=new URL("http://localhost/hao.html");
		System.out.println(url.getPort());
		System.out.println(url.getProtocol());
		System.out.println(url.getHost());
		System.out.println(url.getFile());
		
		System.out.println("download file");
		DownloadFile(url, "F:/hao.html");
	}
	static void DownloadFile(URL url, String luufile) throws Exception{
		InputStream in=url.openStream();
		byte[]buf=new byte[1024];
		int len=0;
		FileOutputStream out=new FileOutputStream(luufile);
		while((len=in.read(buf))!=-1){
			out.write(buf, 0, len);
			out.close();
		}
		System.out.println("download hoan thanh");
	}
}
